<? 
       $p = '1:60';	   
?>


<? 
//@session_start();
 require_once("../includes/config.inc.php"); 
 require_once("../includes/class.mysql.php");
  require_once("../includes/function.in.php");
 $db = New DB();
 $db->connectdb(DB_NAME,DB_USERNAME,DB_PASSWORD);
 $res[times]=$db->select_query("select * from  tb_test_suit   where id_suite='".$_GET['id_suites']."'");
$arr[times] = $db->fetch($res[times]);
$t='00';
$test_time =$arr[times][test_time].':'.$t;

  //$limit='1:60';

  //$p1 = '1:60';
?>
<script>var limit="<?=$test_time?>";</script> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="../csss/style.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
</head>

<body onLoad="begintimer()">
<script language="">

//var limit=$p1;
//var limit="1:60";
if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function begintimer(){
if (!document.images)
return
if (parselimit==0)
// เหตุการณ์ที่ต้องการให้เกิดขึ้น
// window.location='page.php'; ถ้าต้องการให้กระโดดไปยัง Page อื่น
//alert('หมดเวลาแล้วจ้า');
frmTest.submit();
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime="เวลาที่เหลือ <font color=red  font size=20> "+curmin+" </font>นาที กับ <font color=red font size=20>"+cursec+" </font>วินาที "
else
if(cursec==0)
{
alert('หมดเวลาในการทำข้อสอบ');
frmTest.submit();
window.close();
}
else
{
curtime="เวลาที่เหลือ <font color=red font size=20>"+cursec+" </font>วินาที "
}
document.getElementById('dplay').innerHTML = curtime;
setTimeout("begintimer()",1000)
}
}

//-->
</script>
<?


?>

<? if(empty($_GET[action])){?>

<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#99FFCC">
  <tr>
    <td><p>&nbsp;</p>
    <p><div id=dplay ></div></p></td>
  </tr>
</table>

<form id="frmTest" name="frmTest" method="post" action="save.php">
  <table width="100%" height="37" border="1" cellpadding="3" cellspacing="3" bordercolor="#A2B38F">
    <? 
    $db->connectdb(DB_NAME,DB_USERNAME,DB_PASSWORD);
	// เลือกชุดของข้อสอบ----------------------------------------------------
		$count=1;
		$res[s]=$db->select_query("select * from tb_test_suitdetail  where id_suite='".$_GET['id_suites']."'");
		while($arr[s] = $db->fetch($res[s])){
		$ID=$arr[s][ID];
		
		//แสดงหัวข้อคำถาม------------------------------------------------------
	$res[Examination]=$db->select_query("select * from tb_examinationlct where ID='". $ID."' order by   RAND() ");

	//$arr[Examination] = $db->fetch($res[Examination]);
//	echo $arr[Examination][name];
		while($arr[Examination] = $db->fetch($res[Examination])){
		//$IDS= $arr[Examination][ID];
  ?>
    <tr>
      <td><strong>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="80%">
			  <? 
			echo $count.'   ';
			  if($arr[Examination][type_id]==3){
			// echo" <input type='hidden' name='textfield' id='textfield'value=$IDS />";
			  addboxd($arr[Examination][NAME],$arr[Examination][ID]);
			  }else{
			  echo $arr[Examination][NAME]?>
                <? if($arr[Examination][type_id]==2){ ?>
                <a href="#" onClick="MM_openBrWindow('sound.php?media=<?  echo  $arr[Examination][MEDIA]; ?>','','width=300,height=50')" ><img src="../images/sound copy.png" width="20" height="19" /></a>
                <? } }?>
                </td>
          </tr>
          </table>
    <? 
	//แสดง ช้อย-------------------------------------------------------
	  $res[examinationquestion]=$db->select_query("select * from tb_examinationquestion where ID='".$arr[Examination][ID]."'");
						while($arr[examinationquestion] = $db->fetch($res[examinationquestion])){
		
	          	 ?>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="80%" bgcolor="#ECE9D8" >&nbsp;&nbsp;&nbsp;
                  <input name="ch[]<?=$count?>" type="radio" value="<?=$arr[examinationquestion][Q_ID]?>" />
                  <? echo $arr[examinationquestion][Q_NAME] ?>  <? echo $arr[examinationquestion][Q_ID] ?></td>
            </tr>
          </table>
        <? } ?>
      </td>
    </tr>
    <? 
		  $count++;
		  } 
		  
		  }
  ?>
  </table>
  <p>
    <input type="submit" name="button" id="button" value="บันทึกข้อมูล" />
    <input type="hidden" name="id_suite" id="id_suite" value="<? echo $_GET['id_suites'];?>" />
  </p>
</form>
<? } ?>
</body>

</html>
